package org.devocean.groupbuying.dao.impl;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.devocean.groupbuying.dao.LinkStatDAO;
import org.devocean.groupbuying.domain.LinkStat;
import org.springframework.stereotype.Repository;

@Repository
public class LinkStatDAOImpl implements LinkStatDAO {

	@PersistenceContext
	private EntityManager em;


	public List<LinkStat> findAllLinkStats() {
		return em.createQuery("select u from LinkStat u", LinkStat.class)
				.getResultList();
	}

	public long countLinkStat() {
		return em.createQuery("select count(u) from LinkStat u", long.class)
				.getSingleResult();
	}

	public LinkStat findLinkStatById(Integer id) {
		return em.find(LinkStat.class, id);
	}

	public void deleteLinkStat(int id) {
		LinkStat linkStat = em.find(LinkStat.class, id);
		if (linkStat != null) {
			em.remove(linkStat);
		}

	}

	public LinkStat saveLinkStat(LinkStat linkStat) {
		em.persist(linkStat);
		return linkStat;
	}

	public LinkStat updateLinkStat(LinkStat linkStat) {
		em.merge(linkStat);
		return linkStat;
	}
}
